#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int del(int n, int k)
{
    int result = 0;
    for (int i = 2; i <= n; i++)
    {
        result = (result + k) % i;
    }
    return result + 1;
}

int main()
{
    int n, k;
    scanf("%d%d", &n, &k);
    int j = del(n, k);
    printf("%d", j);
    return 0;
}